import type Sequelize_1 from 'sequelize';

type Sequelize = typeof Sequelize_1;
type QueryInterface = Sequelize_1.QueryInterface;

// table name
const table = '${table}';

export async function up(queryInterface: QueryInterface, Sequelize: Sequelize) {
  // Example: run single task
  await queryInterface.createTable(
    table,
    {
      id: { type: Sequelize.INTEGER, allowNull: false, autoIncrement: true, primaryKey: true },
      name: { type: Sequelize.STRING },
    },
    {
      uniqueKeys: {
        name: { fields: ['name'] },
      },
    },
  );

  // Example: run multiple tasks in transaction
  // const transaction = await queryInterface.sequelize.transaction();
  // try {
  //   await queryInterface.renameColumn(table, 'user', 'user_id', { transaction });
  //   await queryInterface.renameColumn(table, 'time', 'capture_time', { transaction });
  //   ...
  //   await transaction.commit();
  // } catch (err) {
  //   await transaction.rollback();
  //   throw err;
  // }
}

export async function down(queryInterface: QueryInterface, Sequelize: Sequelize) {
  // Example: run single task
  await queryInterface.dropTable(table);

  // Example: run multiple tasks in transaction
  // const transaction = await queryInterface.sequelize.transaction();
  // try {
  //   await queryInterface.renameColumn(table, 'user_id', 'user', { transaction });
  //   await queryInterface.renameColumn(table, 'capture_time', 'time', { transaction });
  //   ...
  //   await transaction.commit();
  // } catch (err) {
  //   await transaction.rollback();
  //   throw err;
  // }
}
